<?php 
	/*
	 * changes connection from mysql to using mysqli or PDO for a better next time
	 * settings -> isinya connect + settings global yang dibutuhkan untuk KRS-an
	*/

	//$conn = mysql_connect("localhost","root","");

	// $mysqli = new mysqli("localhost", "root", "", "uwika_krs_alpha");
	try {
		$pdo = new PDO('mysql:host=localhost;dbname=uwika_krs_alpha', 'root', '');
	} catch (PDOException $e) {
		print "Error!: " . $e->getMessage() . "<br/>";
		die();
	}
	
	/*
	if (!mysql_ping($conn)) {
		$conn=mysql_connect("localhost","uwika_krs","l14n54putr1");
		//Lost connection;
	}
	// $mysqli = new mysqli("localhost", "root", "", "uwika_krs");
	try {
		$pdo = new PDO('mysql:host=localhost;dbname=uwika_krs', 'uwika_krs', 'l14n54putr1');
	} catch (PDOException $e) {
		print "Error!: " . $e->getMessage() . "<br/>";
		die();
	}
	// $mysqli = new mysqli("localhost", "uwika_krs", "l14n54putr1", "uwika_krs");
	*/
	
	$sql = "SELECT id_meta_settings, meta_key, meta_value FROM settings_metadata WHERE meta_settings = :meta_settings";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':meta_settings' => 'SETTINGS.GLOBAL' ));
	while($_data = $stmt->fetch(PDO::FETCH_ASSOC)){
		$_global_settings[$_data['id_meta_settings']]->$_data['meta_key'] = $_data['meta_value'];
	}

	function getLevelSettings($obj_level, $obj_pdo){
		$sql = "SELECT meta_key, meta_value FROM settings_metadata WHERE meta_settings = :meta_settings AND id_meta_settings = :id_meta_settings";
		$stmt_level_settings = $obj_pdo->prepare($sql);
		$stmt_level_settings->execute(array(':meta_settings' => 'SECURITY.LEVEL' 
											,':id_meta_settings' => $obj_level));
		while($_data_level_settings = $stmt_level_settings->fetch(PDO::FETCH_ASSOC)){
			if( $_data_level_settings['meta_key'] == 'menu'){
				$obj_unserialize = unserialize($_data_level_settings['meta_value']);
				$obj_level_settings->$_data_level_settings['meta_key'] = $obj_unserialize;
			}else{
				$obj_level_settings->$_data_level_settings['meta_key'] = $_data_level_settings['meta_value'];
			}
		}
		return $obj_level_settings;		
	}
	
	function getJurusan($obj_kode, $obj_pdo){
		$sql = "SELECT * FROM jurusan WHERE kode_jurusan = :kode_jurusan";
		$stmt_get_jurusan = $obj_pdo->prepare($sql);
		$stmt_get_jurusan->execute(array(':id_meta_settings' => $obj_level));
		$_data_get_jurusan = $stmt_get_jurusan->fetch(PDO::FETCH_OBJ);
		return $obj_get_jurusan;
	}
	//var_dump($_global_settings);
	//var_dump($_global_settings['semester']);
	//echo $_global_settings['semester']->value;
?>